import cv2
import os

input_movie = cv2.VideoCapture("/media/cjg/Elements/pano20210902/20210901_video/data.mp4")
length = int(input_movie.get(cv2.CAP_PROP_FRAME_COUNT))

path="" 

sub = "Img"
subpath = os.path.join(path, sub)
if not os.path.exists(subpath):
    os.mkdir(subpath)

sub_resized = "Img_resized"
subpath_resized = os.path.join(path, sub_resized)
if not os.path.exists(subpath_resized):
    os.mkdir(subpath_resized)

init = 0

nImage = 0

while True:
    # Grab a single frame of video
    ret, frame = input_movie.read()
 
    # Quit when the input video file ends
    if not ret:
        break
    
    if init is 0:
        scale_percent = 100
        width = int(frame.shape[1] * scale_percent / 100.0)
        height = int(frame.shape[0] * scale_percent / 100.0)
        dim = (width, height)
        init = 1
    
    # milliseconds = input_movie.get(cv2.CAP_PROP_POS_MSEC)
    # milliseconds *= 0.001
    cv2.imwrite(subpath+"/mask.jpg", frame)
    # frame1 = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA)
    # cv2.imwrite(subpath_resized+"/"+str(milliseconds)+".jpg", frame1)
    print("ds")

    nImage = nImage+1
    
print(nImage)
